package cn.edu.jxau.test;

public class Point implements Comparable<Point> {

    private int x;
    private int y;
    private int z;

    public Point() {

    }

    public Point(int x, int y, int z) {

        this.x = x;
        this.y = y;
        this.z = z;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getZ() {
        return z;
    }

    public void setZ(int z) {
        this.z = z;
    }

    /**
     * 三维空间下，两点之间距离公式:Math.sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2)
     * @return
     */
    public double distance() {
        return Math.sqrt(x * x + y * y + z * z);
    }

    @Override
    public int compareTo(Point p) {

        double d1 = distance();
        double d2 = p.distance();
        if (d1 < d2) {
            return -1;
        } else if (d1 > d2) {
            return 1;
        } else {
            return 0;
        }
    }

    @Override
    public String toString() {
        return String.format("(%3d,%3d,%3d)\tdistance=%.2f", x, y, z, distance());
    }
}
